var e = require("../../../@babel/runtime/helpers/defineProperty"), t = getApp();

Page({
    data: {
        business_hours_start: "00:00",
        business_hours_end: "24:00",
        imageList: [],
        imagefile1: "",
        imagefile2: "",
        imagefile3: "",
        provinceData: [],
        cityData: [],
        districtData: [],
        pickerValue: [ 0, 0, 0 ],
        realname: "",
        deliver_name: "",
        deliver_mobile: "",
        address: "",
        full_address: ""
    },
    onLoad: function(e) {
        this._initAddressInfo(), this.getData();
    },
    getData: function() {
        var e = this, a = t.getNetAddresss("plugin.package-deliver.frontend.deliver.editDeliver");
        t._getNetWork({
            url: a,
            success: function(t) {
                var a = t.data;
                if (console.log(a), 1 != a.result) return !1;
                var s = a.data.deliver, i = s.realname, r = s.deliver_name, d = s.deliver_mobile, n = s.address, o = s.full_address, c = s.thumb, l = JSON.parse(JSON.stringify(c)), u = s.aptitute, g = s.id_card_front, m = s.id_card_side, f = s.business_hours_start, p = s.business_hours_end, h = {};
                h.province_id = s.province_id, h.city_id = s.city_id, h.district_id = s.district_id, 
                h.street_id = s.street_id, e.setData({
                    realname: i,
                    deliver_name: r,
                    deliver_mobile: d,
                    address: n,
                    full_address: o,
                    imageList: c,
                    imagefile1: u,
                    imagefile2: g,
                    tempImageList: l,
                    imagefile3: m,
                    business_hours_start: f,
                    business_hours_end: p,
                    apply: h
                }), e.selseadress(), h.district_id && 0 != h.district_id && (e.setData({
                    strShow: !0
                }), e.bj_getStreet(h.district_id));
            }
        });
    },
    pushData: function() {
        var e = this, a = this.data, s = a.realname, i = a.deliver_name, r = a.deliver_mobile, d = a.address, n = a.apply, o = a.business_hours_start, c = a.business_hours_end, l = this.data.imageList, u = this.data.imagefile1, g = this.data.imagefile2, m = this.data.imagefile3, f = n.province_id, p = n.city_id, h = n.district_id, _ = n.street_id;
        if (t._isTextEmpty(s)) return this.tips("姓名不能为空");
        if (t._isTextEmpty(i)) return this.tips("提货卡不能为空");
        if (t._isTextEmpty(r)) return this.tips("提货卡不能为空");
        if (t._isTextEmpty(d)) return this.tips("详细地址不能为空");
        if (l.length < 0) return this.tips("请上传自提点图片");
        var v = t.getNetAddresss("plugin.package-deliver.frontend.deliver.editDeliver"), D = {
            realname: s,
            deliver_name: i,
            deliver_mobile: r,
            address: d,
            business_hours_start: o,
            business_hours_end: c,
            thumb: l,
            aptitute: u,
            id_card_front: g,
            id_card_side: m,
            province_id: f,
            city_id: p,
            district_id: h,
            street_id: _
        };
        t._postNetWork({
            url: v,
            data: {
                deliver: D
            },
            success: function(t) {
                var a = t.data;
                if (console.log(a), 1 != a.result) return e.tips(a.msg);
                wx.navigateBack();
            }
        });
    },
    selseadress: function() {
        var e = wx.getStorageSync("provinceData"), t = wx.getStorageSync("cityData"), a = wx.getStorageSync("districtData");
        console.log(this.data.form), console.log(e);
        var s = "", i = "", r = "";
        for (var d in e) e[d].id == this.data.apply.province_id && (s = e[d].areaname);
        for (var n in t) t[n].id == this.data.apply.city_id && (i = t[n].areaname);
        for (var o in a) a[o].id == this.data.apply.district_id && (r = a[o].areaname);
        var c = "".concat(s).concat(i).concat(r);
        this.setData({
            addressName: c
        });
    },
    bj_getStreet: function(e) {
        console.log(e);
        var a = this, s = t.getNetAddresss("member.memberAddress.street");
        s += "&district_id=" + e, t._getNetWork({
            url: s,
            success: function(e) {
                var s = e.data;
                if (1 != s.result || t._isTextEmpty(s.data)) a.setData({
                    strShow: !1
                }); else if (!t._isTextEmpty(s.data) && s.data.length > 0) for (var i = 0; i < s.data.length; i++) console.log(a.data.apply.street_id), 
                s.data[i].id == a.data.apply.street_id && (a.setData({
                    street: s.data[i].areaname,
                    districtVal: s.data
                }), console.log(s.data[i].areaname)); else a.setData({
                    strShow: !1
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    onRead_1: function(a) {
        var s = a.currentTarget.dataset.index, i = this, r = t.getNetAddresss("upload.uploadPic");
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                var a = t.tempFilePaths;
                console.log(a[0]);
                var d = a[0];
                wx.uploadFile({
                    url: r,
                    filePath: d,
                    name: "file",
                    success: function(t) {
                        var a = JSON.parse(t.data);
                        if (1 != a.result) return wx.showToast({
                            icon: "none",
                            title: a.msg,
                            duration: 1500
                        }), !1;
                        var r = "imagefile" + s;
                        i.setData(e({}, r, a.data.img_url));
                    }
                });
            }
        });
    },
    treetShowLeft: function() {
        this.setData({
            streetShow: !1
        });
    },
    onReady: function() {},
    addressShowbtn: function() {
        this.setData({
            addressShow: !0
        });
    },
    bindStartTimeChange: function(e) {
        console.log(e.detail.value), this.setData({
            business_hours_start: e.detail.value
        });
    },
    bindEndTimeChange: function(e) {
        this.setData({
            business_hours_end: e.detail.value
        });
    },
    onShow: function() {},
    onRead_6: function() {
        var e = this;
        wx.chooseImage({
            count: 9,
            sizeType: [ "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                e.unload({
                    tempFilePaths: t.tempFilePaths
                }, 6);
            }
        });
    },
    onRead_5: function() {
        var e = this;
        wx.chooseImage({
            count: 9,
            sizeType: [ "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                e.unload({
                    tempFilePaths: t.tempFilePaths
                }, 5);
            }
        });
    },
    unload: function(e, a) {
        var s = this, i = t.getNetAddresss("upload.uploadPic"), r = e.i ? e.i : 0, d = e.success ? e.success : 0, n = e.fail ? e.fail : 0;
        wx.uploadFile({
            url: i,
            filePath: e.tempFilePaths[r],
            name: "file",
            formData: null,
            success: function(e) {
                var t = JSON.parse(e.data);
                if (1 != t.result) return n++, s.tips(t.msg);
                5 == a ? (s.data.imagefile1.push(t.data.img_url), s.setData({
                    imagefile1: s.data.imagefile1
                })) : 6 == a && (s.data.imageList.push(t.data.img_url), s.setData({
                    imageList: s.data.imageList
                }));
            },
            fail: function(e) {
                n++;
            },
            complete: function(t) {
                ++r == e.tempFilePaths.length ? (console.log("执行完毕"), console.log("成功：" + d + " 失败：" + n)) : (e.i = r, 
                e.success = d, e.fail = n, this.unload(e, a));
            }
        });
    },
    bindChange: function(e) {
        var t = e.detail.value;
        this.data.pickerValue[0] != t[0] && (t[1] = 0, t[2] = 0), this.data.pickerValue[1] != t[1] && (t[2] = 0), 
        this.setData({
            "pickerValue[0]": t[0],
            "pickerValue[1]": t[1],
            "pickerValue[2]": t[2]
        }), this._initAddressInfo();
    },
    _closeDateLw: function() {
        this.setData({
            addressShow: !1
        });
    },
    streetShowbtn: function() {
        this.setData({
            streetShow: !0
        });
    },
    streetConfirm: function(e) {
        var t = e.currentTarget.dataset.item;
        this.setData({
            street: t.areaname,
            "apply.street_id": t.id,
            streetShow: !1
        });
    },
    resultAdd: function() {
        var e = this.data.selectAddressData, t = e[0].name + " " + e[1].name + " " + e[2].name;
        this.setData({
            addressName: t,
            provice: e[0].name,
            city: e[1].name,
            district: e[2].name
        }), this.setData({
            "apply.province_id": e[0].id,
            "apply.city_id": e[1].id,
            "apply.district_id": e[2].id,
            addressShow: !1
        }), this.getStreet(e[2].id);
    },
    getStreet: function(e) {
        var a = this, s = "";
        s += t.getNetAddresss("member.memberAddress.street"), s += "&district_id=" + e, 
        t._getNetWork({
            url: s,
            success: function(e) {
                var s = e.data;
                1 == s.result && !t._isTextEmpty(s.data) && s.data.length > 0 ? a.setData({
                    districtVal: s.data,
                    strShow: !0
                }) : a.setData({
                    strShow: !1
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    _initAddressInfo: function() {
        var e = this;
        wx.getStorage({
            key: "provinceData",
            success: function(t) {
                console.log("地址信息准备就绪"), e._getProvinceData();
            },
            fail: function(a) {
                console.log("省fail"), t._getNetWork({
                    url: t.getNetAddresss("member.member-address.address"),
                    success: function(t) {
                        var a = t.data, s = a.data.province, i = a.data.city, r = a.data.district;
                        wx.setStorage({
                            key: "provinceData",
                            data: s
                        }), wx.setStorage({
                            key: "cityData",
                            data: i
                        }), wx.setStorage({
                            key: "districtData",
                            data: r
                        }), e._initAddressInfo();
                    },
                    fail: function(e) {},
                    state: !0
                });
            }
        });
    },
    _getProvinceData: function() {
        var e = this;
        wx.getStorage({
            key: "provinceData",
            success: function(t) {
                console.log("省读取成功", t.data), e.setData({
                    provinceData: t.data
                }), e.setData({
                    "selectAddressData[0].name": t.data[e.data.pickerValue[0]].areaname,
                    "selectAddressData[0].id": t.data[e.data.pickerValue[0]].id,
                    "selectAddressData[0].index": e.data.pickerValue[0]
                }), e._getCityData();
            }
        });
    },
    _getCityData: function() {
        var e = this.data.selectAddressData[0];
        console.log("城市", "_data", e);
        var t = this;
        wx.getStorage({
            key: "cityData",
            success: function(a) {
                console.log("城市读取成功", a);
                for (var s = [], i = 0; i < a.data.length; i++) a.data[i].parentid == e.id && s.push(a.data[i]);
                console.log("城市数据筛选", s), t.setData({
                    cityData: s
                }), t.setData({
                    "selectAddressData[1].name": s[t.data.pickerValue[1]].areaname,
                    "selectAddressData[1].id": s[t.data.pickerValue[1]].id,
                    "selectAddressData[1].index": t.data.pickerValue[1]
                }), t._getDistrictData();
            }
        });
    },
    _getDistrictData: function() {
        var e = this.data.selectAddressData[1];
        console.log("地区", "_data", e), console.log(e);
        var t = this;
        wx.getStorage({
            key: "districtData",
            success: function(a) {
                console.log("地区读取成功");
                for (var s = [], i = 0; i < a.data.length; i++) a.data[i].parentid == e.id && s.push(a.data[i]);
                console.log("地区数据筛选", s), t.setData({
                    districtData: s
                }), console.log("districtData", s), t.setData({
                    "selectAddressData[2].name": s[t.data.pickerValue[2]].areaname,
                    "selectAddressData[2].id": s[t.data.pickerValue[2]].id,
                    "selectAddressData[2].index": t.data.pickerValue[2]
                }), console.log("over", t.data.selectAddressData);
            }
        });
    },
    onHide: function() {},
    tips: function(e) {
        return wx.showToast({
            title: e,
            icon: "none"
        }), !1;
    },
    onUnload: function() {},
    delIntu_6: function(e) {
        var t = this.data.imageList, a = e.currentTarget.id;
        t.splice(a, 1), this.setData({
            imageList: t
        });
    },
    delIntu_5: function(e) {
        var t = this.data.imagefile1, a = e.currentTarget.id;
        t.splice(a, 1), this.setData({
            imagefile1: t
        });
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});